<%@page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib uri="TowkerTagLib" prefix="rbac"%>
<%@include file="/commons/include/html_doctype.html"%>
<html>
<head>
	<title>修改</title>
	<%@include file="/commons/include/upd.jsp" %>
	<script type="text/javascript">
$(function(){
	
	jQuery("#dataForm").validate(
	{
		goods_sn:{
			required:true
		},
		goods_name:{
			required:true
		},
		type_id:{
			required:true
		},
		class_id:{
			required:true
		},
		attr:{
			required:true
		}
		,
		messages: {
			goods_sn:{
				required:"请填写品种代码"
			},
			goods_name:{
				required:"请填写品种名称"
			},
			type_id:{
				required:"请选择品种大类"
			},
			class_id:{
				required:"请选择品种小类"
			},
			attr:{
				required:"请选择品种性质"
			} 
		 
			 
		},
		submitHandler:function(form)
		{
			jQuery.ajax({
				url : ctx + '/manage/basicData/checkExistsGoodsSn.htm',
				type : "POST",
				data : {id:$('#goodsId').val(),goods_sn:$('#goods_sn').val()},
				dataType : "json",
				success : function(d) {
				if(!d.result)
					jQuery(form).ajaxSubmit(_options);
				else
					alert('品种代码有重复!');
				},error:function(){
				   alert('后台验证品种代码出错');
				}
			});	
		}
	});
	
	
	$("#attr").change(function(){
		   var attr = $(this);
		   rawStock( attr .val());
		});
	
	   rawStock( $("#attr").val() );
		
});
_callback = function() {
	location.href = ctx + "/manage/basicData/getGoods.htm";
}
validCallBack = function()
{
	//添加页面自定义校验
	if($("#alarm").val()=="需要" && $("#stock_tips").val()==""){
		alert("请填写库存报警的最低库存量");
		return false;
	}
	return true;
};

function rawStock( val ){
	 var jprice_tile =   $("#jprice_tile") ;
	  var jprice =  $("#jpricetd");
	 
  if ( val == 4 ){
	 //  raw_stock();
	   

	   $("#isnot_raw_stock").hide();
	   $("#tprice_title").hide();
	   $("#tpricetd").hide();
	   jprice.show();
	   jprice_tile.show();
	 // $("#raw_stock").append('<td class="form_title" id="jprice_tile">计划单价：</td><td class="form_input" id="jpricetd"><input type="text" id="jprice" name="jprice" value="" /></td>'); 
	
  }else{
	 //  isnot_raw_stock();
	   $("#isnot_raw_stock").show();
	   $("#tprice_title").show();
	   $("#tpricetd").show();
	     jprice_tile.hide(); 
		  jprice.hide();
		 
	 //  $("#lasttr").prepend('<td class="form_title" id="jprice_tile">计划单价：</td><td class="form_input" id="jpricetd"><input type="text" id="jprice" name="jprice" value="" /></td>'); 
		
  }
}
	</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="listLogo">
	<tr>
		<td class="title">物料修改</td>
		<td>
			<div class="menuTool">
				<a class="save" id="dataFormSave" href="#">保存</a>
				<a class="back" href="getGoods.htm">返回</a>
			</div>
		</td>
	</tr>
</table>
<div class="line"></div>
<form id="dataForm" method="post" action="updGoods2.htm">
<table border="0" cellspacing="1" cellpadding="0" class="listTable">
	<tr>
	<td class="form_title">品种代码：</td>
		<td class="form_input"><input type="text" id="goods_sn" name="goods_sn" value="${fn:escapeXml(po.goods_sn)}" /></td>
		
		<td class="form_title">品种名称：</td>
		<td class="form_input"><input type="text" id="goods_name" name="goods_name" value="${fn:escapeXml(po.goods_name)}" /></td>
		<td class="form_title">品种型号：</td>
		<td class="form_input"><input type="text" id="spec" name="spec" value="${fn:escapeXml(po.spec)}" /></td>
	</tr>
	<tr>
		<td class="form_title">品种大类号：</td>
		<td class="form_input">
		<select id="type_id" name="type_id">
			 <c:forEach items="${goodsBigClassList}" var="d" varStatus="status">
					<option value="${d.id}" <c:if test="${d.id==po.type_id }">selected="selected"</c:if> >${d.class_name}[${d.calss_code }]</option>
				</c:forEach>
		</select>
		</td>
	   <td class="form_title">品种小类号：</td>
		<td class="form_input">
		<select id="class_id" name="class_id">
				 <c:forEach items="${goodsClassList}" var="d" varStatus="status">
					<option value="${d.id}" <c:if test="${d.id==po.class_id }">selected="selected"</c:if> >${d.class_name}</option>
				</c:forEach>
		</select>
		</td>
	
	<td class="form_title">品种性质：</td>
		<td class="form_input">
		<select id="attr" name="attr">
			<option value="1" <c:if test="${po.attr==1 }">selected="selected"</c:if> >常规产品</option>
			<option value="2" <c:if test="${po.attr==2 }">selected="selected"</c:if> >定做产品</option>
			<option value="3" <c:if test="${po.attr==3 }">selected="selected"</c:if> >外购商品</option>
			<option value="4" <c:if test="${po.attr==4 }">selected="selected"</c:if> >原材料</option>
		</select>
		</td>
	</tr>
	<tr id="raw_stock">
	
		<td class="form_title">计量单位：</td>
	   <td class="form_input"><input type="text" id="unit" name="unit" value="${fn:escapeXml(po.unit)}" /></td>
	
		<td class="form_title">单位重量：</td>
		<td class="form_input"><input type="text" id="weight" name="weight" value="${fn:escapeXml(po.weight)}" /></td>
		  <td class="form_title" id="tprice_title">调拨价：</td>
		<td class="form_input" id="tpricetd"> <input type="text" id="tprice" name="tprice" value="${fn:escapeXml(po.tprice)}" /> </td>

		<td class="form_title" id="jprice_tile" style="display: none">计划单价：</td>
		<td class="form_input" id="jpricetd"  style="display: none"><input type="text" id="jprice" name="jprice" value="${fn:escapeXml(po.jprice)}" /></td>
	</tr>
	<tr id="isnot_raw_stock">
	
	 <td class="form_title">商业价：</td>
	<td class="form_input"><input type="text" id="bprice" name="bprice" value="${fn:escapeXml(po.bprice)}" /></td>
	 <td class="form_title">零售价：</td>
	  	  <td class="form_input"><input type="text" id="sprice" name="sprice" value="${fn:escapeXml(po.sprice)}" /></td>
   <td class="form_title">批发价：</td>
	  <td class="form_input"><input type="text" id="wprice" name="wprice" value="${fn:escapeXml(po.wprice)}" /></td>
 
	
    </tr>
	<tr id="lasttr">
	<!-- 
	<td class="form_title">计划单价：</td>
		<td class="form_input"><input type="text" id="jprice" name="jprice" value="" /></td>
	
	<td class="form_title">产品单位：</td>
		<td class="form_input"><input type="text" id="unit" name="unit" value="" /></td>
	  <td class="form_title">商业价：</td>
	  <td class="form_input"><input type="text" id="bprice" name="bprice" value="" /></td>
	
	  <td class="form_title">批发价：</td>
	  <td class="form_input"><input type="text" id="wprice" name="wprice" value="" /></td>
		   <td class="form_title">零售价：</td>
	  <td class="form_input"><input type="text" id="sprice" name="sprice" value="" /></td>  
		<td class="form_title" id="jprice_tile" >计划单价：</td>
		<td class="form_input" id="jpricetd"><input type="text" id="jprice" name="jprice" value="" /></td>
	-->
	  	
	    <td class="form_title">是否需要报警：</td>
	  <td class="form_input"><select id="alarm" name="alarm">
			<option value="不需要" <c:if test="${po.alarm=='不需要' }">selected="selected"</c:if> >不需要</option>
			<option value="需要"   <c:if test="${po.alarm=='需要' }">selected="selected"</c:if> >需要</option>
	  </select></td>
	  <td class="form_title">库存报警的最低库存量：</td>
	  <td class="form_input" colspan="3"><input type="text" id="stock_tips" name="stock_tips" value="${fn:escapeXml(po.stock_tips)}" /></td>
    
    </tr>
</table>
<input type="hidden" name="down_order" value="${po.down_order}" />
<input type="hidden" name="stock" value="${po.stock}" />
<input type="hidden" name="down_order_total" value="${po.down_order_total}" />
<input type="hidden" name="id" id="goodsId" value="${po.id}" />
</form>
</body>
</html>
